/**
 * Created by elead on 2018/10/29.
 */

//location.origin
function myAjax(url,data,successCallback,errCallback,type){
    if(data.datalist!=undefined){
        data=trims(data)
    }
    data=JSON.stringify(data);
    if(type!=""&&type!=undefined ){
        type="&type="+type
    }else{
        type="";
    }
    var urlHref1=location.origin
    var urlHref2=location.protocol+"//"+location.hostname;
    if(urlHref1=="http://localhost:63342"){
        url="https://www.easy-mock.com/mock/5bd18ddb18d3a27e0c5b9221/data"+url+"?param="+encodeURIComponent(data)
    }else{
        if(type==""){
            url=urlHref2+"/Windchill/app/ECOChange"+url+"?param="+encodeURIComponent(data);
        }else{
            url=urlHref2+"/Windchill/app/ECOChange"+url+"?param="+encodeURIComponent(data)+type;
        }

    }
        $.ajax({
            headers: {
                username:"TIANMA",
                password:"TIANMA"
            },
            type:"post",
          //url:"https://www.easy-mock.com/mock/5bd18ddb18d3a27e0c5b9221/data"+url+"?param="+data,
            url:url,
            dataType:"String",
            data:{},
            complete:function(msg){
                var str = msg.responseText;
                str = eval("("+str+")");
                successCallback(str);

            }
        })

}
function myAjaxData(url,data,successCallback,errCallback){
    if(data.datalist!=undefined){
        data=trims(data)
    }
    data=JSON.stringify(data);
    var urlHref1=location.origin
    var urlHref2=location.protocol+"//"+location.hostname;
    if(urlHref1=="http://localhost:63342"){
        url="https://www.easy-mock.com/mock/5bd18ddb18d3a27e0c5b9221/data"+url+"?data="+encodeURIComponent(data);
    }else{
        url=urlHref2+"/Windchill/app/ECOChange"+url+"?data="+encodeURIComponent(data);
    }
    $.ajax({
        headers: {
            username:"TIANMA",
            password:"TIANMA"
        },
        type:"post",
        //url:"https://www.easy-mock.com/mock/5bd18ddb18d3a27e0c5b9221/data"+url+"?param="+data,
        url:url,
        dataType:"String",
        data:{},
        complete:function(msg){
            var str = msg.responseText;
            str = eval("("+str+")");
            successCallback(str);
        }
    })

}
function myAjaxHistory(url,data,successCallback,errCallback){
   // data=encodeURIComponent(data);
    var urlHref1=location.origin
    var urlHref2=location.protocol+"//"+location.hostname;
    if(urlHref1=="http://localhost:63342"){
        url="https://www.easy-mock.com/mock/5bd18ddb18d3a27e0c5b9221/data"+url+"?"+encodeURIComponent(data);
    }else{
        url=urlHref2+"/Windchill/app/ECOChange"+url+"?"+data;
    }
    $.ajax({
        headers: {
            username:"TIANMA",
            password:"TIANMA"
        },
        type:"post",
        //url:"https://www.easy-mock.com/mock/5bd18ddb18d3a27e0c5b9221/data"+url+"?"+data,
        url:url,
        dataType:"String",
        data:{},
        complete:function(msg){
            var str = msg.responseText;

            str = eval("("+str+")");
            successCallback(str);

        }
    })

}

function myAjaxEcoHistory(url,data,successCallback,errCallback){
    //data=encodeURIComponent(data);
    var urlHref1=location.origin
    var urlHref2=location.protocol+"//"+location.hostname;
    if(urlHref1=="http://localhost:63342"){
        url="https://www.easy-mock.com/mock/5bd18ddb18d3a27e0c5b9221/data"+url+"?"+encodeURIComponent(data);
    }else{
        url=urlHref2+"/Windchill/app/ECOChange"+url+"?"+data;
    }
    $.ajax({
        headers: {
            username:"TIANMA",
            password:"TIANMA"
        },
        type:"post",
        //url:"https://www.easy-mock.com/mock/5bd18ddb18d3a27e0c5b9221/data"+url+"?"+data,
        url:url,
        dataType:"String",
        data:{},
        complete:function(msg){
            var str = msg.responseText;

            str = eval("("+str+")");
            successCallback(str);

        }
    })

}

//http://plmdev.tianma.cn/Windchill/app/MaterialReverse/tmMaterialReverse?

function MaterialReverseAjax(url,data,successCallback,errCallback){
    // data=encodeURIComponent(data);
    var urlHref1=location.origin
    var urlHref2=location.protocol+"//"+location.hostname;
    if(urlHref1=="http://localhost:63342"){
        url="https://www.easy-mock.com/mock/5bd18ddb18d3a27e0c5b9221/data"+url+"?"+encodeURIComponent(data);
    }else{
        url=urlHref2+"/Windchill/app"+url+"?"+data;
    }
    $.ajax({
        headers: {
            username:"TIANMA",
            password:"TIANMA"
        },
        type:"post",
        //url:"https://www.easy-mock.com/mock/5bd18ddb18d3a27e0c5b9221/data"+url+"?"+data,
        url:url,
        dataType:"String",
        data:{},
        complete:function(msg){
            var str = msg.responseText;

            str = eval("("+str+")");
            successCallback(str);

        }
    })

}

function MaterialReverseAjax1(url,data,successCallback,errCallback){
    // data=encodeURIComponent(data);
    var urlHref1=location.origin
    var urlHref2=location.protocol+"//"+location.hostname;
    /*if(urlHref1=="http://localhost:63342"){*/
        url="https://www.easy-mock.com/mock/5bd18ddb18d3a27e0c5b9221/data"+url+"?"+encodeURIComponent(data);
   /* }else{
        url=urlHref2+"/Windchill/app"+url+"?"+data;
    }*/
    $.ajax({
        headers: {
            username:"TIANMA",
            password:"TIANMA"
        },
        type:"post",
        //url:"https://www.easy-mock.com/mock/5bd18ddb18d3a27e0c5b9221/data"+url+"?"+data,
        url:url,
        dataType:"String",
        data:{},
        complete:function(msg){
            var str = msg.responseText;

            str = eval("("+str+")");
            successCallback(str);

        }
    })

}

function ajaxNewFn(url,data,successCallback,errCallback){
    if(data.datalist!=undefined){
        data=trims(data)
    }
    data=JSON.stringify(data);
    var urlHref1=location.origin
    var urlHref2=location.protocol+"//"+location.hostname;
    if(urlHref1=="http://localhost:63342"){
        url="https://www.easy-mock.com/mock/5bd18ddb18d3a27e0c5b9221/data"+url
    }else{
        url=urlHref2+"/Windchill/app"+url;
    }
    $.ajax({
        headers: {
            username:"TIANMA",
            password:"TIANMA"
        },
        type:"post",
        //url:"https://www.easy-mock.com/mock/5bd18ddb18d3a27e0c5b9221/data"+url+"?"+data,
        url:url,
        contentType: "text/html; charset=utf-8",
        dataType:"text",
        data:data,
        complete:function(msg){
            var str = msg.responseText;

            str = eval("("+str+")");
            successCallback(str);

        }
    })
}
function ajaxNewFnTwo(url,data,successCallback,errCallback){
    if(data.datalist!=undefined){
        data=trims(data)
    }
    console.log(typeof data)
    //data=JSON.stringify(data);
    var urlHref1=location.origin
    var urlHref2=location.protocol+"//"+location.hostname;
    if(urlHref1=="http://localhost:63342"){
        url="https://www.easy-mock.com/mock/5bd18ddb18d3a27e0c5b9221/data"+url
    }else{
        url=urlHref2+"/Windchill/app"+url;
    }
    $.ajax({
        headers: {
            username:"TIANMA",
            password:"TIANMA"
        },
        type:"post",
        //url:"https://www.easy-mock.com/mock/5bd18ddb18d3a27e0c5b9221/data"+url+"?"+data,
        url:url,
      /*  contentType: "application/json; charset=utf-8",*/
        dataType:"json",
        data:data,
        complete:function(msg){
            var str = msg.responseText;

            str = eval("("+str+")");
            successCallback(str);

        }
    })
}